import math

from .Constant import *
from Utils.DiskUtils import *

class DBR:
    def __init__(self, data: str):
        self.hide_sectors = data[64 * BYTES: (64 + 8) * BYTES]
        self.total_sectors = data[72 * BYTES: (72 + 8) * BYTES]
        self.FAT_origin = data[80 * BYTES: (80 + 4) * BYTES]
        self.FAT_storage = data[84 * BYTES: (84 * 4) * BYTES]
        self.cluster_origin = data[88 * BYTES: (88 + 4) * BYTES]
        self.partition_total_cluster = data[92 * BYTES: (92 + 4) * BYTES]
        self.root_catalog_cluster_number = data[96 * BYTES: (96 + 4) * BYTES]
        self.per_cluster = data[109 * BYTES: (109 + 1) * BYTES]

    def get_per_cluster_of_sectors(self):
        r = self.__get(self.per_cluster)
        return math.pow(2, r)

    def get_cluster_origin(self):
        return self.__get(self.cluster_origin)

    def get_root_catalog_number(self):
        return self.__get(self.root_catalog_cluster_number)

    def __get(self, get: str):
        return int(reserve_bytes(get), 16)